package com.hwua.view;

import com.hwua.domain.Car;
import com.hwua.service.CarService;
import com.hwua.serviceimpl.CarServiceImpl;
import com.hwua.util.InputTools;

import java.sql.SQLException;
import java.util.List;

/**
 * 还车界面
 * @author admin
 */
public class ReturnCarView extends AbstractView{
    private int num2;
    private String name;
    private String pwd;
    /**
     *判断是哪个界面(汽车查询界面/租车记录查询界面)
     */
    private String view;
    public ReturnCarView(int num2,String name,String pwd,String view){
        this.num2=num2;
        this.name=name;
        this.pwd=pwd;
        this.view=view;
    }
    @Override
    public AbstractView showView() {
        CarService cs = new CarServiceImpl();
        List<Car> carList7 = null;
        try {
            System.out.println("是否选择折扣优惠券结算？（1.是 2.否）：");
            int choose = InputTools.checkIntInput(1, 2);
            //调用还车方法，传入当前用户名，汽车id，是否打折的选项
            carList7 = cs.returnCarById(name, num2,choose);
            if(!carList7.isEmpty()){
                System.out.println("还车成功！还车信息如下：");
                System.out.println("=================================================================还车记录" +
                        "=======================================================");
                System.out.println("编号\t汽车名称\t日租金\t\t总租金\t\t品牌\t\t类型\t\t颜色\t\t备注\t\t借车时间\t\t\t\t\t还车时间");
                for (Car car : carList7) {
                    System.out.println(car.getRecordId()+"\t\t"+car.getCarName()+"\t\t"+car.getDailyRent()+"\t\t"+car.getPayment()+
                            "\t\t"+car.getBrand()+"\t\t"+car.getType()+"\t\t"+car.getColor()+"\t\t"+car.getCarRemark()
                            + "\t"+car.getRentTime()+"\t\t"+car.getReturnTime());
                }
                if("汽车查询界面".equals(view)){
                    nextView=new UserView(name,pwd);
                }else if("租车记录界面".equals(view)){
                    nextView=new UserLookRecordView(name,pwd);
                }
            }
        } catch (NullPointerException e) {
            nextView=new UserLookRecordView(name,pwd);
        }
        return nextView;
    }
}
